﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NHibernate.Tool.hbm2ddl;

namespace Nh.Web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            var session = MvcApplication.SessionFactory.GetCurrentSession();
            using (var tans = session.BeginTransaction())
            {
                //session.Save(new Eg.Core.Product()
                //{
                //    Description = "Nh mapp6ing!",
                //    Name = "nhcoo6kbo6ok",
                //    UnitPrice = 346m
                //});

                //session.Save(new Eg.Core.Orders() { CreateTime = DateTime.Now, Price = 160, State = Eg.Core.OrderState.Complete });
                //Eg.Core.Users user = new Eg.Core.Users(){ CreateTime = DateTime.Now, Password = "21212", UserName = "Mecekyz"};
                //Eg.Core.UserDetail userDetail = new Eg.Core.UserDetail() { LastUpdate = DateTime.Now, Name = new Eg.Core.PersonName() { FirstName = "Zhuo", LastName = "Bin" }, Users = user };
                //user.Detail = userDetail;
                //session.Save(new Eg.Core.Users() { CreateTime = DateTime.Now, Password = "123456", UserName = "Mecekyz" });
                
                //session.Save(new Eg.Core.Blog() { Title = "Blogs!" });
                //session.Save(user);
                //session.Flush();

                //Eg.Core.Customer customer = new Eg.Core.Customer() { FirstName = "Zhuo", LastName = "Bin" };
                ////ISet<Eg.Core.Orders> Orders = new ISet<Eg.Core.Orders>();
                //var order1 = new Eg.Core.Orders() { Customer = customer, CreateTime = DateTime.Now, Price = 100, State = Eg.Core.OrderState.Complete };
                //var order2 = new Eg.Core.Orders() { Customer = customer, CreateTime = DateTime.Now, Price = 200, State = Eg.Core.OrderState.Complete };
                
                //session.Save(customer);
                //session.Save(order1);
                //session.Save(order2);
                //session.Flush();

                Eg.Core.Movie movie = new Eg.Core.Movie() {  Description = "Ice age 4", Director = "Mecekyz", Name = "Ice agr 4.", UnitPrice = 70};
                IList<Eg.Core.ActorRole> actors = new List<Eg.Core.ActorRole>();
                actors.Add(new Eg.Core.ActorRole() { Movie = movie, Actor = "Mecekyz", Role = "Mouse" });
                actors.Add(new Eg.Core.ActorRole() { Movie = movie, Actor = "Mecekyz", Role = "Elepemnt" });
                movie.Actors = actors;
                session.Save(movie);
                tans.Commit();
            }
            return View();
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
